package de.core.geometrics;

import java.awt.geom.Point2D;

public class Vector2D {
    private final double x;
    private final double y;


    /**
     * Creates an empty Vector at (0,0).
     */
    public Vector2D() {
        this(0, 0);
    }

    /**
     * Creates an {@link Vector2D} from the coordinates of a {@link Point2D}.
     */
    public Vector2D(Point2D aPoint) {
        this(aPoint.getX(), aPoint.getY());
    }

    public Vector2D(double aX, double aY) {
        x = aX;
        y = aY;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    /**
     * Returns the length of this {@link Vector2D}.
     */
    public double getLength() {
        return Math.hypot(x, y);
    }

    /**
     * Returns a new created {@link Vector2D} wich length is increased by the
     * passed Factor.
     */
    public Vector2D increaseLength(double aFactor) {
        return new Vector2D(getX() * aFactor, getY() * aFactor);
    }

    /**
     * Returns the dot product between this and the passed {@link Vector2D}.
     */
    public double getDotProduct(Vector2D aVector) {
        return getX() * aVector.getX() + getY() * aVector.getY();
    }

    /**
     * Returns the angle between this and the passed {@link Vector2D}.
     */
    public double getAngle(Vector2D aVector) {
        double radians = Math.acos(getDotProduct(aVector) / (getLength() * aVector.getLength()));
        return 360 / (2 * Math.PI) * radians;
    }


}
